package com.donglan.pethome.organization.service.impl;

import com.donglan.pethome.basic.service.impl.BaseServiceImpl;
import com.donglan.pethome.organization.domain.Employee;
import com.donglan.pethome.organization.domain.Shop;
import com.donglan.pethome.organization.mapper.EmployeeMapper;
import com.donglan.pethome.organization.mapper.ShopMapper;
import com.donglan.pethome.organization.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author: zhangdonghui
 * @Date: 2022/1/11 15:09
 */
@Service
public class ShopServiceImpl extends BaseServiceImpl<Shop> implements ShopService {


    @Autowired
    private EmployeeMapper employeeMapper;
    @Autowired
    private ShopMapper shopMapper;

    /*
     * 功能描述 店铺入驻
     * @author zhangdonghui
     * @date 2022/1/11 15:12
     * @param shop 
     * @return void
     */
    @Override
    @Transactional
    public void settledIn(Shop shop) {
        // 获取店铺管理员对象
        Employee admin = shop.getAdmin();
        // 保存管理员对象
        // 同时返回新增数据的id值，该id需要赋值给t_shop的admin_id
        employeeMapper.add(admin);
        // 保存店铺
        shopMapper.add(shop);
        System.out.println(shop);
    }

    /*
     * 功能描述 根据后台登录用户id查询店铺对象
     * @author zhangdonghui
     * @date 2022/2/15 18:47
     * @param employeeId
     * @return com.donglan.pethome.organization.domain.Shop
     */
    @Override
    public Shop loadShopByEmployeeId(Long employeeId) {
        return shopMapper.loadShopByEmployeeId(employeeId);
    }
}
